package org.xukai.common.util;

/**
 * @author xukai
 * @desc
 * @date 2017-04-19-9:31
 */

import java.util.LinkedHashMap;
import java.util.Map;

public class LRUCache<K, V> extends LinkedHashMap<K, V> {

    private int cacheSize;

    public LRUCache(int cacheSize) {
        super(16, 0.75f, true);
        this.cacheSize = cacheSize;
    }

    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > cacheSize;
    }



    public static void main(String[] args) {
        LRUCache frame = new LRUCache(4);
        frame.put("7",7);
        frame.put("6",6);
        frame.put("0",0);
        frame.put("1",1);
        System.out.println(frame.get("7"));
    }

}